﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KFC.MonAnF
{
    public class MonAnFactory
    {
        private static List<MonAn> _samples = new List<MonAn>();

        public List<MonAn> Samples
        {
            get { return MonAnFactory._samples; }
        }

        private static List<MonAn> _dsLoaiMonAn;
        public static List<MonAn> _dsMonAn;
        ServiceReferenceKFC.Service1SoapClient client;
        public MonAnFactory()
        {
            KhoiTaoDSLoaiMonAn();
            client = new ServiceReferenceKFC.Service1SoapClient();
            
        }

        public void KhoiTaoDSLoaiMonAn()
        {
            _samples = new List<MonAn>();
            _dsLoaiMonAn = new List<MonAn>();
            _dsLoaiMonAn.Add(new GaRanTruyenThong());
            _dsLoaiMonAn.Add(new ThucAnNhe());
            _dsLoaiMonAn.Add(new ThucAnPhu());
            _dsLoaiMonAn.Add(new MonTrangMiengGiaiKhat());
            _dsLoaiMonAn.Add(new PhanAnCombo());
            _dsLoaiMonAn.Add(new PhanAnTreEm());
            _samples = _dsLoaiMonAn;
        }
        public List<MonAn> LayDSGaRanTruyenThong()
        {
            return null;
        }
        public void KhoiTaoDanhSachMonAn()
        {
            _dsMonAn = LayDSMonAn();
        }
    
        public static void add(MonAn ma)
        {
            for (int i = 0; i < _samples.Count; i++)
            {
                if (ma.LayTenLoaiDoiTuong() == _samples[i].LayTenLoaiDoiTuong())
                    return;
            }

            _samples.Add(ma);
        }

        public MonAn GetMonAn(int idx)
        {
            if (idx >= 0 && idx < _samples.Count)
            {
                return _samples[idx].Clone();
            }
            return null;
        }

        public static MonAn Produce(string strMonAnType)
        {
            for (int i = 0; i < _samples.Count; i++)
            {
                if (_samples[i].LayTenLoaiDoiTuong() == strMonAnType)
                    return _samples[i].Clone();
            }
            return null;
        }

        public List<MonAn> LayDSMonAn()
        {
           
            var list = client.GetDSMon();
            List<MonAn> kq = new List<MonAn>();

            foreach (var i in list)
            {
                MonAn m = Produce(i.LoaiDoiTuong);
                m.SetInforFrom(i);
                kq.Add(m);
            }
            return kq;
        }
        public static List<String> LayDSThuocTinhMonAn()
        {
            List<string> kq = new List<string>();
            kq.Add("Mã món ăn");
            kq.Add("Tên món ăn");
            kq.Add("Đơn giá");
            kq.Add("Chi tiết");
            kq.Add("Số lượng");
            kq.Add("Loại đối tượng");
            return kq;
        }
        //public List<MonAn> HuyMonAn(String MaMonAn)
        //{
        //    client.HuyMonAn(MaMonAn);
        //    List<MonAn> mas = (from m in _dsMonAn
        //                where m.MaMonAn == MaMonAn
        //                select m).ToList();
        //    if (mas.Count > 0)
        //    {
        //        _dsMonAn.Remove(mas[0]);
        //    }
        //    return _dsMonAn;
        //}
    }
}
